![]() |
Kinetis SDK Demo Applications User Guide
1.0.0-beta
Freescale Semiconductor, Inc.
|
#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include <stdarg.h>#include "device/fsl_device_registers.h"#include "uart/fsl_uart_driver.h"#include "fsl_uart_hal.h"#include "smc/fsl_smc_manager.h"#include "fsl_smc_features.h"#include "fsl_smc_hal.h"#include "gpio/fsl_gpio_driver.h"#include "interrupt/fsl_interrupt_manager.h"#include "clock/fsl_clock_manager.h"#include "fsl_port_hal.h"#include "fsl_sim_hal.h"#include "fsl_mcg_hal.h"#include "fsl_osc_hal.h"#include "board.h"#include "low_power_demo.h"#include "fsl_pmc_hal.h"Functions | |
| void | llwu_isr (void) |
| LLWU ISR function. More... | |
| void | cpu_identify (void) |
| cpu identification function for K22F120M More... | |
| void | de_init_pins (void) |
| void | main (void) |
| main function. More... | |
| void | port_init (void) |
| configure tower/freedom hardware port pins for the application More... | |
| void | led_init (void) |
| configure LED pins for the tower/freedom hardware More... | |
| int32_t | fll_freq (int32_t fllRef) |
| returns the Frequency Locked Loop frequency More... | |
| uint8_t | what_mcg_mode (void) |
| returns the the current MCG mode More... | |
| int32_t | pee_to_blpe (void) |
| switch from PEE mode to BLPE mode More... | |
| int32_t | blpe_to_pee (void) |
| switch from BLPE mode to PEE mode More... | |
| void | set_for_lp (uint8_t outOfLp) |
| Settings done before swithing in low power mode. More... | |
| void | enter_vlls0 (uint8_t PORPOValue) |
| VLLS0 mode entry routine. Puts the processor into VLLS0 mode from normal run mode or VLPR. More... | |
| void | enter_vlls1 (void) |
| VLLS1 mode entry routine. Puts the processor into VLLS1 mode from normal run mode or VLPR. More... | |
| void | enter_vlls2 (void) |
| VLLS2 mode entry routine. Puts the processor into VLLS2 mode from normal run mode or VLPR. More... | |
| void | enter_vlps (void) |
| enter in VLPS mode More... | |
| void | enter_vlls3 (void) |
| enter in VLLS3 mode More... | |
| void | enter_lls (void) |
| LLS mode entry routine. Puts the processor into LLS mode from normal run mode or VLPR. More... | |
| void | exit_vlpr (void) |
| VLPR mode exit routine. Puts the processor into normal run mode from VLPR mode. You can transition from VLPR to normal run using this function. More... | |
| int32_t | enter_vlpr (void) |
| VLPR mode entry routine.Puts the processor into very low power run mode. In this mode all clocks are enabled, but the core clock limited. The flash clock is limited to 1MHz or less. More... | |
| void | enter_wait (power_modes_t pMode) |
| WAIT mode entry routine. Puts the processor into wait mode. In this mode the core clock is disabled (no code executing), but bus clocks are enabled (peripheral modules are operational). More... | |
| void | enter_stop (smc_stop_submode_t partialStopOpt) |
| STOP mode entry routine. Puts the processor into normal stop mode. In this mode core, bus and peripheral clocks are disabled. More... | |
| void | vlp_clock_config (int8_t nextMode) |
| clock configuration for very low power More... | |
| void | demo_lptmr_isr (void) |
| ISR Routine for Low Power Timer. More... | |
| void | lptmr_init (uint32_t count, uint32_t clockSource) |
| Low Power Timer initialization routine. More... | |
| void | llwu_init (void) |
| initializes LLWU module More... | |
| void | low_power_modes_test (void) |
| main low power mode test routine More... | |
| int32_t | pee_pbe (int32_t crystalVal) |
| switches from PEE to PBE mode More... | |
| int32_t | pbe_pee (int32_t crystalVal) |
| switches from PBE to PEE mode More... | |
| int32_t | pbe_fbe (int32_t crystalVal) |
| switches from PBE to FBE mode More... | |
| int32_t | fbe_pbe (int32_t crystalVal, int8_t prDivVal, int8_t vDivVal) |
| switches from FBE to PBE mode This function transitions the MCG from FBE mode to PBE mode. This function presently only supports OSC0 and PLL0. Support for OSC1 and PLL1 will be added soon The function requires the desired OSC and PLL be passed in to it for compatibility with the future support of OSC/PLL selection More... | |
| int32_t | pbe_blpe (int32_t crystalVal) |
| switches from PBE to BLPE mode More... | |
| int32_t | blpe_pbe (int32_t crystalVal, int8_t prDivVal, int8_t vDivVal) |
| switches from BLPE to PBE mode Since PBE mode can be enterred via FBE -> BLPE modes, it cannot be assumed that the PLL has been previously configured correctly. That is why this general purpose driver has the PLL settings as passed parameters. More... | |
| int32_t | blpe_fbe (int32_t crystalVal) |
| switches from BLPE to FBE mode More... | |
| int32_t | fbe_blpe (int32_t crystalVal) |
| switches from FBE to PLPE mode More... | |
| int32_t | fei_fbe (int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal) |
| switches from FEI to FBE mode More... | |
| int32_t | fee_fbe (int32_t crystalVal) |
| switches from FEE to FBE mode More... | |
| int32_t | fbe_fbi (int32_t ircFreq, uint8_t ircSelect) |
| switches from FBE to PLPE mode More... | |
| int32_t | fbi_fbe (int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal) |
| switches from FBI to FBE mode More... | |
| int32_t | fbi_blpi (int32_t ircFreq, uint8_t ircSelect) |
| switches from FBI to BLPI mode This function transitions the MCG from FBI mode to BLPI mode. This is achieved by setting the MCG_C2[LP] bit. There is no status bit to check so 0 is always returned if the function was called with the MCG in FBI mode. More... | |
| int32_t | blpi_fbi (int32_t ircFreq, uint8_t ircSelect) |
| switches from BLPI to FBI mode More... | |
| int32_t | fee_fbi (int32_t ircFreq, uint8_t ircSelect) |
| switches from FEE to FBI mode More... | |
| int32_t | fbi_fei (int32_t slowIrcFreqInner) |
| switches from FBI to FEI mode More... | |
| int32_t | fei_fbi (int32_t ircFreq, uint8_t ircSelect) |
| switches from FEI to FBI mode More... | |
| int32_t | fei_fee (int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal) |
| switches from FEI to FEE mode More... | |
| int32_t | fee_fei (int32_t slowIrcFreqInner) |
| switches from More... | |
| uint8_t | atc (uint8_t ircSelect, int32_t ircFreq, int32_t mcgOutFreq) |
| configure for MCG auto trimming More... | |
| int32_t | pll_init (int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal, int8_t prDivVal, int8_t vDivVal, uint8_t mcgOutSelect) |
| Option to move from FEI to PEE mode or to just initialize the PLL. More... | |
| void | out_srs (void) |
| checks the value in the SRS registers and sends messages to the terminal announcing the status at the start of the code. More... | |
| void | port_isr (void) |
| Port ISR routine for the on board switch. More... | |
| void | HardFault_Handler (void) |
Variables | |
| uint8_t | s_uartInstance |
| uint8_t | uartEnabled |
| static uart_state_t | uartState |
| static uart_user_config_t | uartConfig |
| int32_t | fastIrcFreq |
| int32_t | slowIrcFreq |
| int32_t | mcgClkHz |
| int32_t | mcgClkKhz |
| int32_t | coreClkKhz |
| int32_t | periphClkKhz |
| int32_t | pllClkKhz |
| int32_t | uart0ClkKhz |
| uint32_t | uart0ClkHz |
| uint32_t | uartClkHz |
| uint8_t atc | ( | uint8_t | ircSelect, |
| int32_t | ircFreq, | ||
| int32_t | mcgOutFreq | ||
| ) |
| ircSelect | - 0 if slow irc, 1 if fast irc |
| ircFreq | - IRC frequency |
| mcgOutFreq | - MCG output frequency |
| int32_t blpe_fbe | ( | int32_t | crystalVal | ) |
| crystalVal | - external clock frequency in Hz |
| int32_t blpe_pbe | ( | int32_t | crystalVal, |
| int8_t | prDivVal, | ||
| int8_t | vDivVal | ||
| ) |
| crystalVal | - external clock frequency in Hz |
| prDivVal | - value to divide the external clock source by to create the desired PLL reference clock frequency |
| vDivVal | - value to multiply the PLL reference clock frequency by Return value : MCGCLKOUT frequency (Hz) or error code |
| int32_t blpe_to_pee | ( | void | ) |
| int32_t blpi_fbi | ( | int32_t | ircFreq, |
| uint8_t | ircSelect | ||
| ) |
This function transitions the MCG from BLPI mode to FBI mode. This is achieved by clearing the MCG_C2[LP] bit. There is no status bit to check so 0 is always returned if the function was called with the MCG in BLPI mode.
| ircFreq | - IRC clock frequency |
| ircSelect | - 0 if slow irc, 1 if fast irc Return value : MCGOUT frequency or error code |
| void cpu_identify | ( | void | ) |
cpu identification function for K22F120M
| void de_init_pins | ( | void | ) |
| void demo_lptmr_isr | ( | void | ) |
| void enter_lls | ( | void | ) |
Mode transitions: RUN -> LLS VLPR -> LLS
NOTE: LLS mode will always exit to RUN mode even if you were in VLPR mode before entering LLS.
Wakeup from LLS mode is controlled by the LLWU module. Most modules cannot issue a wakeup interrupt in LLS mode, so make sure to setup the desired wakeup sources in the LLWU before calling this function.
| void enter_stop | ( | smc_stop_submode_t | partialStopOpt | ) |
Mode transitions: RUN -> STOP
This function can be used to enter normal stop mode. If you are executing in normal run mode when calling this function and AVLP = 0, then you will enter normal stop mode. If AVLP = 1 with previous write to PMPROT then you will enter VLPS mode instead.
STOP mode is exited using any enabled interrupt or RESET, so no exit_stop routine is needed.
| partialStopOpt | - Partial Stop Option: 0x00 = STOP - Normal Stop Mode 0x40 = PSTOP1 - Partial Stop with both system and bus clocks disabled 0x80 = PSTOP2 - Partial Stop with system clock disabled and bus clock enabled 0xC0 = Reserved |
| void enter_vlls0 | ( | uint8_t | PORPOValue | ) |
Mode transitions:
RUN -> VLLS0, VLPR -> VLLS0
NOTE: VLLSx modes will always exit to RUN mode even if you were in VLPR mode before entering VLLSx.
Wakeup from VLLSx mode is controlled by the LLWU module. Most modules cannot issue a wakeup interrupt in VLLSx mode, so make sure to setup the desired wakeup sources in the LLWU before calling this function.
| PORPOValue | - POR detect circuit is enabled/disabled
|
| void enter_vlls1 | ( | void | ) |
Mode transitions: RUN -> VLLS1 VLPR -> VLLS1
NOTE: VLLSx modes will always exit to RUN mode even if you were in VLPR mode before entering VLLSx.
Wakeup from VLLSx mode is controlled by the LLWU module. Most modules cannot issue a wakeup interrupt in VLLSx mode, so make sure to setup the desired wakeup sources in the LLWU before calling this function.
| void enter_vlls2 | ( | void | ) |
Mode transitions: RUN -> VLLS2 VLPR -> VLLS2
NOTE: VLLSx modes will always exit to RUN mode even if you were in VLPR mode before entering VLLSx.
Wakeup from VLLSx mode is controlled by the LLWU module. Most modules cannot issue a wakeup interrupt in VLLSx mode, so make sure to setup the desired wakeup sources in the LLWU before calling this function.
| void enter_vlls3 | ( | void | ) |
| int32_t enter_vlpr | ( | void | ) |
Mode transitions: RUN -> VLPR
exit_vlpr() function can be used to switch from VLPR back to RUN.
while in VLPR,VLPW or VLPS the exit to VLPR is not possible
PMSTAT = 000_0001 Current power mode is RUN
= 000_0100 Current power mode is VLPR
ERROR Code = 0x14 - already in VLPR mode
= 0x24 - REGONS never clear indicating stop regulation | void enter_vlps | ( | void | ) |
| void enter_wait | ( | power_modes_t | pMode | ) |
Mode transitions: RUN -> WAIT VLPR -> VLPW
This function can be used to enter normal wait mode or VLPW mode. If you are executing in normal run mode when calling this function, then you will enter normal wait mode. If you are in VLPR mode when calling this function, then you will enter VLPW mode instead.
NOTE: Some modules include a programmable option to disable them in wait mode. If those modules are programmed to disable in wait mode, they will not be able to generate interrupts to wake up the core.
WAIT mode is exited using any enabled interrupt or RESET, so no exit_wait routine is needed.
| pMode | - specify the specific wait modes = kPowerModeVlpw to enter in VLPW mode
= kPowerModeWait to enter in WAIT mode |
| void exit_vlpr | ( | void | ) |
Mode transitions: VLPR -> RUN
| int32_t fbe_blpe | ( | int32_t | crystalVal | ) |
| crystalVal | - external clock frequency in Hz |
| int32_t fbe_fbi | ( | int32_t | ircFreq, |
| uint8_t | ircSelect | ||
| ) |
| ircFreq | - IRC clock frequency |
| ircSelect | - 0 if slow irc, 1 if fast irc |
| int32_t fbe_pbe | ( | int32_t | crystalVal, |
| int8_t | prDivVal, | ||
| int8_t | vDivVal | ||
| ) |
| crystalVal | - external clock frequency in Hz |
| prDivVal | - value to divide the external clock source by to create the desired PLL reference clock frequency |
| vDivVal | - value to multiply the PLL reference clock frequency by Return value : MCGCLKOUT frequency (Hz) or error code |
| int32_t fbi_blpi | ( | int32_t | ircFreq, |
| uint8_t | ircSelect | ||
| ) |
| ircFreq | - IRC clock frequency |
| ircSelect | - 0 if slow irc, 1 if fast irc Return value : MCGOUT frequency or error code |
| int32_t fbi_fbe | ( | int32_t | crystalVal, |
| mcg_hgo_select_t | hgoVal, | ||
| mcg_eref_clock_select_t | erefsVal | ||
| ) |
| crystalVal | - external clock frequency in Hz |
| hgoVal | - selects whether low power or high gain mode is selected for the crystal oscillator. This has no meaning if an external clock is used. |
| erefsVal | - selects external clock (=kMcgErefClockSelectExt) or crystal osc (=kMcgErefClockSelectOsc) Return value : MCGCLKOUT frequency (Hz) or error code |
| int32_t fbi_fei | ( | int32_t | slowIrcFreqInner | ) |
| slowIrcFreqInner | - slow IRD frequency |
| int32_t fee_fbe | ( | int32_t | crystalVal | ) |
| crystalVal | - external clock frequency in Hz |
| int32_t fee_fbi | ( | int32_t | ircFreq, |
| uint8_t | ircSelect | ||
| ) |
| ircFreq | - IRC clock frequency |
| ircSelect | - 0 if slow irc, 1 if fast irc Return value : MCGOUT frequency or error code |
| int32_t fee_fei | ( | int32_t | slowIrcFreqInner | ) |
| slowIrcFreqInner | - slow IRC frequency |
| int32_t fei_fbe | ( | int32_t | crystalVal, |
| mcg_hgo_select_t | hgoVal, | ||
| mcg_eref_clock_select_t | erefsVal | ||
| ) |
Mode transition: FEI to FBE mode
This function transitions the MCG from FEI mode to FBE mode. This is achieved by setting the MCG_C2[LP] bit. There is no status bit to check so 0 is always returned if the function was called with the MCG in FBI mode. The MCGCLKOUT frequency does not change
| crystalVal | - external clock frequency in Hz |
| hgoVal | - selects whether low power or high gain mode is selected for the crystal oscillator. This has no meaning if an external clock is used. |
| erefsVal | - selects external clock (=kMcgErefClockSelectExt) or crystal osc (=kMcgErefClockSelectOsc) Return value : MCGCLKOUT frequency (Hz) or error code |
| int32_t fei_fbi | ( | int32_t | ircFreq, |
| uint8_t | ircSelect | ||
| ) |
| ircFreq | - IRC clock frequency |
| ircSelect | - 0 if slow irc, 1 if fast irc |
| int32_t fei_fee | ( | int32_t | crystalVal, |
| mcg_hgo_select_t | hgoVal, | ||
| mcg_eref_clock_select_t | erefsVal | ||
| ) |
This function transitions the MCG from FEI mode to FEE mode. This is achieved by setting the MCG_C2[LP] bit. There is no status bit to check so 0 is always returned if the function was called with the MCG in FBI mode. The MCGCLKOUT frequency does not change
| crystalVal | - external clock frequency in Hz |
| hgoVal | - selects whether low power or high gain mode is selected for the crystal oscillator. This has no meaning if an external clock is used. |
| erefsVal | - selects external clock (=kMcgErefClockSelectExt) or crystal osc (=kMcgErefClockSelectOsc) Return value : MCGCLKOUT frequency (Hz) or error code |
| int32_t fll_freq | ( | int32_t | fllRef | ) |
| fllRef | - reference FLL frequency |
| void HardFault_Handler | ( | void | ) |
| void led_init | ( | void | ) |
| void llwu_init | ( | void | ) |
| void llwu_isr | ( | void | ) |
| void low_power_modes_test | ( | void | ) |
| void lptmr_init | ( | uint32_t | count, |
| uint32_t | clockSource | ||
| ) |
| count | - initialize timer for 'count' miliseconds |
| clockSource | - clock source |
| void main | ( | void | ) |
| void out_srs | ( | void | ) |
| int32_t pbe_blpe | ( | int32_t | crystalVal | ) |
| crystalVal | - crystal value |
| int32_t pbe_fbe | ( | int32_t | crystalVal | ) |
| crystalVal | - crystal value |
| int32_t pbe_pee | ( | int32_t | crystalVal | ) |
| crystalVal | - crystal value |
| int32_t pee_pbe | ( | int32_t | crystalVal | ) |
| crystalVal | - crystal value |
| int32_t pee_to_blpe | ( | void | ) |
| int32_t pll_init | ( | int32_t | crystalVal, |
| mcg_hgo_select_t | hgoVal, | ||
| mcg_eref_clock_select_t | erefsVal, | ||
| int8_t | prDivVal, | ||
| int8_t | vDivVal, | ||
| uint8_t | mcgOutSelect | ||
| ) |
| crystalVal | - external clock frequency in Hz either from a crystal or square wave clock source |
| hgoVal | - selects whether low power or high gain mode is selected for the crystal oscillator. This has no meaning if an external clock is used. |
| erefsVal | - selects external clock (=0) or crystal osc (=1) |
| prdivVal | - value to divide the external clock source by to create the desired PLL reference clock frequency |
| vdivVal | - value to multiply the PLL reference clock frequency by |
| mcgOutSelect | - 0 if the PLL is just to be enabled, non-zero if the PLL is used to provide the MCGOUT clock for the system. |
Return value : PLL frequency (Hz) or error code
| void port_init | ( | void | ) |
| void port_isr | ( | void | ) |
| void set_for_lp | ( | uint8_t | outOfLp | ) |
| outOfLp | - indicate whether to do the setting for going in/coming out of low power mode = 0 for going into low power mode
= 1 for exiting low power mode |
| void vlp_clock_config | ( | int8_t | nextMode | ) |
| nextMode | = BLPI or BLPE |
| uint8_t what_mcg_mode | ( | void | ) |
| int32_t coreClkKhz |
Core clock frequency in KHz
| int32_t fastIrcFreq |
default fast irc frequency
| int32_t mcgClkHz |
MCG out clock frequecy in Hz
| int32_t mcgClkKhz |
MCG out clock frequency in KHz
| int32_t periphClkKhz |
Peripheral clock frequency in KHz
| int32_t pllClkKhz |
PLL clock frequency in KHz
| uint8_t s_uartInstance |
uart instance for the target
| int32_t slowIrcFreq |
default slow irc frequency
| uint32_t uart0ClkHz |
UART0 clock frequency in Hz
| int32_t uart0ClkKhz |
UART0 clock frequency in KHz
| uint32_t uartClkHz |
Other uart clock frequcy in Hz
|
static |
| uint8_t uartEnabled |
indicates whether the uart port is currently enabled or not
|
static |
uart state information